package com.chuangyang.fixboxmaster.ui.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.chuangyang.fixboxlib.utils.StringUtils;
import com.chuangyang.fixboxmaster.AppData;
import com.chuangyang.fixboxmaster.R;
import com.chuangyang.fixboxmaster.bean.NewOrder;
import com.chuangyang.fixboxmaster.ui.fragment.OrderListFragment;

import java.util.ArrayList;

/**
 * Created by vanshu on 15/4/9 11:22.
 */
public class OrderListAdapter extends BaseAdapter {
    private ArrayList<NewOrder> orders = new ArrayList<>();

    public int mCurrentType;
    public OrderListAdapter(ArrayList<NewOrder> orders){
        this.orders=orders;
    }

    @Override
    public int getCount() {
        return orders == null ? 0 : orders.size();
    }

    @Override
    public Object getItem(int position) {
        return orders.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    public void setCurrentType(int type){
        mCurrentType = type;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(AppData.getContext()).inflate(R.layout.order_list_view_item, parent, false);
            holder = new ViewHolder();
            holder.mOrderTitle = (TextView) convertView.findViewById(R.id.order_title);
            holder.mOrderStatus = (TextView) convertView.findViewById(R.id.order_status);
            holder.mOrderCreateTime = (TextView) convertView.findViewById(R.id.order_create_time);
            holder.mOrderMoney = (TextView) convertView.findViewById(R.id.order_money);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.mOrderTitle.setText(orders.get(position).title);
        holder.mOrderStatus.setText(orders.get(position).statusDesc);
        holder.mOrderCreateTime.setText(StringUtils.convertDate(orders.get(position).createDate));
        if (mCurrentType == OrderListFragment.ORDER_HISTORY)
        {
            holder.mOrderMoney.setText(String.valueOf(orders.get(position).totalPrice)+"元");
        }
        else
        {
            holder.mOrderMoney.setText(String.valueOf(orders.get(position).totalPrice)+"元");
        }

        return convertView;
    }


    public static class ViewHolder{
        public TextView mOrderTitle;
        public TextView mOrderStatus;
        public TextView mOrderCreateTime;
        public TextView mOrderMoney;
    }

}
